<template>
    项目名称:<input type="text" v-model="info.Iname"/>
    最小投资额:<input type="text" v-model="info.minIsum"/>
    最大投资额:<input type="text" v-model="info.maxIsum"/>
    <button @click="ShowInvest">查询</button>
<table border="1">
    <tr>
        <td>投资项目名称</td>
        <td>总额度</td>
        <td>已投金额</td>
        <td>剩余额度</td>
        <td>投资次数</td>
        <td>操作</td>
    </tr>
    <tr v-for="i in data">
        <td>{{ i.Iname }}</td>
        <td>{{ i.Isum.toFixed(2)}}CNY</td>
        <td>{{ i.Iyprice.toFixed(2) }}CNY</td>
        <td>{{ i.Isprice.toFixed(2) }}CNY</td>
        <td>{{ i.Inum.toFixed(2) }}CNY</td>
        <td><a href="#" @click="DeleteById(i.Iid)">删除</a></td>
    </tr>
</table>
<a href="#" @click="PageChange('F')">首页</a>
<a href="#" @click="PageChange('P')">上一页</a>
<a href="#" @click="PageChange('N')">下一页</a>
<a href="#" @click="PageChange('L')">尾页</a>
当前页数:{{ Page.PageIndex }} 总页数:{{ Page.PageCount }} 总记录数:{{ Page.ReCount }}
</template>
<script setup lang="ts">
import axios from 'axios';
import { ref,onMounted } from 'vue';
const data=ref([
    {
        Iid:0,
        Iname:'',
        Isum:0,
        Isprice:0,
        Iyprice:0,
        Inum:0
    }
])
const Page=ref(
    {
        PageSize:2,
        PageIndex:1,
        ReCount:0,
        PageCount:0
    }
)
const info = ref(
    {
        Iname:"",
        minIsum:"",
        maxIsum:""
    }
)
onMounted(()=>{
    ShowInvest()
})
const ShowInvest=()=>{
    axios.get('https://localhost:44368/api/Lx/PageShow',
        {
            params:{
                PageSize:Page.value.PageSize,
                PageIndex:Page.value.PageIndex,
                Iname:info.value.Iname,
                minIsum:info.value.minIsum,
                maxIsum:info.value.maxIsum
            }
        }
    )
    .then(res=>{
        data.value=res.data.list
        Page.value.ReCount=res.data.ReCount
        Page.value.PageCount=res.data.PageCount
    })
    .catch(err=>{
        console.log(err);
    })
}
const DeleteById=(Iid:number)=>{
    if(!confirm("是否删除")){
        return
    }
    axios.get('https://localhost:44368/api/Lx/DeleteById',{
        params:{
            Iid:Iid
        }
    })
    .then(res=>{
        if(res.data>0){
            alert("删除成功")
            ShowInvest()
        }else if(res.data==-1){
            alert("该投资项目有投资记录，无法删除")
        }
        else{
            alert("删除失败")
        }
    })
    .catch(err=>{
        console.log(err);
    })
}
const PageChange=(msg:string)=>{
    if(msg=="F"){
        Page.value.PageIndex=1
        ShowInvest()
    }else if(msg=="N"){
        if(Page.value.PageIndex==Page.value.PageCount){
            alert("已经是最后一页了")
            return
        }
        Page.value.PageIndex=Page.value.PageIndex+1
        ShowInvest()
    }else if(msg=="P"){
        if(Page.value.PageIndex==1){
            alert("已经是第一页了")
            return
        }
        Page.value.PageIndex=Page.value.PageIndex-1
        ShowInvest()
    }else if(msg=="L"){
        Page.value.PageIndex=Page.value.PageCount
        ShowInvest()
    }
}


</script>